<?php
namespace Esseak\FetchPackage;

use Illuminate\Support\Facades\Route;
use Illuminate\Support\ServiceProvider;
use Esseak\FetchPackage\Console\PublishCommand;
use Esseak\FetchPackage\Console\InstallCommand;
use Esseak\FetchPackage\Console\FetchDatasCommand;
use Dcat\Admin\Admin;
use Illuminate\Routing\Router;


class FetchServiceProvider extends ServiceProvider{

    /**
     * Register services.
     *
     * @return void
     */
    public function register()
    {
        //
    }

    /**
     * Bootstrap services.
     *
     * @return void
     */
    public function boot()
    {
        //

        if ($this->app->runningInConsole()) {
            $this->commands([
                PublishCommand::class,
                InstallCommand::class,
                FetchDatasCommand::class,
            ]);
        }

        if(env('DB_CONNECTION') == 'sqlite'){
            $this->publishes([
                __DIR__ . '/database/database.sqlite'=>env('DB_DATABASE', database_path('database.sqlite'))
            ]);
        }

        //数据库迁移文件
        $migrationFiles = '2022_06_06_000001_create_videos_table.php';
        $this->publishes([
            __DIR__ . "/database/migrations/{$migrationFiles}"=>database_path("migrations/{$migrationFiles}")
        ]);

        //路由
        Route::middleware('api')->prefix('api')->group(function () {
            $this->loadRoutesFrom(__DIR__ . '/routes/api.php');
        });

        //后台路由
        Route::group([
            'prefix'     => config('admin.route.prefix'),
            'namespace'  => 'Esseak\FetchPackage\Admin\Controllers',
            'middleware' => config('admin.route.middleware'),
        ], function (Router $router) {
        
            $router->resource('/videos', 'VideosController');
        
        });
        

    }
}